home *** CD-ROM | disk | FTP | other *** search
/ Directorty Opus 5 - Magellan 2 / Opus 5 - Magellan 2.iso / Extras / D51_NUSource / Source / Routines / Clipboard.s < prev    next >
Text File  |  1995-08-27  |  8KB  |  204 lines

  1. * Force both PushChunk things to fail, to see if CloseIFF works.
  2.  
  3. *=- INFO -=****************************************************************************
  4. * Routines for reading from/writting to the clipboard.                      *
  5. * Unless otherwise stated, all routines are by Leo Davidson (Pot-Noodle of Gods'Gift) *
  6. *=- Notes -===========================================================================*
  7. * o Includes routines for handling IFF files. These may be moved at some point.          *
  8. *=- To Do -===========================================================================*
  9. ***************************************************************************************
  10.  
  11.  
  12. ***************************************************************************************
  13. * Clipboard Subroutines                                      *
  14. ***************************************************************************************
  15. ;Include Asm:Source/Routines/Clipboard.s
  16.  
  17.  
  18. *= Write To Clipboard =************************************************= 25-Aug-1995 =*
  19. *  Inputs: (a1) - Text to put into clipboard.                          *
  20. *           d0  - Length of (a1).                              *
  21. * Outputs: Text is written to the clipbaord (IFF-Text/FTXT format).              *
  22. *   Notes: Failure will abort the program.                          *
  23. ***************************************************************************************
  24. WriteToClip
  25.     Movem.l    a1/d0,-(SP)            Preserve buffer/size.
  26.  
  27.     Bsr    AllocNudelIFF            Allocate IFFHandle.
  28.     Move.l    NudelIFFHandle(a5),a0        -._ Initialise it for
  29.     N_CallIFFParse    InitIFFasClip        -'  the clipboard.
  30.     Bsr    OpenNudelClipboard        Open the clipboard and setup stream.
  31.     Moveq    #IFFF_WRITE,d0            -._ Open the IFFHandle,
  32.     Bsr    OpenNudelIFF            -'  in WRITE mode.
  33.  
  34.     Move.l    NudelIFFHandle(a5),a0        IFFHandle,
  35.     Move.l    #"FTXT",d0            Type,
  36.     Move.l    #ID_FORM,d1            id,
  37.     Moveq    #IFFSIZE_UNKNOWN,d2        Let it handle the size itself.
  38.     N_CallIFFParse    PushChunk        Push an IFF-Text chunk.
  39.     Tst.l    d0
  40.     Bne    PushChunk_Error_1
  41.  
  42.     Move.l    NudelIFFHandle(a5),a0        IFFHandle,
  43.     Moveq    #0,d0                Type,
  44.     Move.l    #"CHRS",d1            id,
  45.     Moveq    #IFFSIZE_UNKNOWN,d2        Let it handle the size itself.
  46.     N_CallIFFParse    PushChunk        Push an IFF-Text chunk.
  47.     Tst.l    d0
  48.     Bne    PushChunk_Error_2
  49.  
  50.     Move.l    NudelIFFHandle(a5),a0        IFFHandle.
  51.     Movem.l    (SP)+,a1/d0            Restore buffer/size.
  52.     N_CallIFFParse    WriteChunkBytes        Write buffer to clipboard.
  53.     Tst.l    d0                -._ If negative result,
  54.     Blt.s    WriteChunkBytes_Error        -'  call special error routine.
  55.  
  56.     Move.l    NudelIFFHandle(a5),a0        -._ Pop the previously
  57.     N_CallIFFParse    PopChunk        -'  pushed chunk.
  58.     Tst.l    d0
  59.     Bne_ErrorE_Int    ErrAct_IFFPopChunk(pc),#0
  60.  
  61.     Move.l    NudelIFFHandle(a5),a0        -._ Pop the previously
  62.     N_CallIFFParse    PopChunk        -'  pushed chunk.
  63.     Tst.l    d0
  64.     Bne_ErrorE_Int    ErrAct_IFFPopChunk(pc),#0
  65.  
  66.     Bsr    CloseNudelIFF        Close our IFFhandle.
  67.     Bsr    FreeNudelIFF        Free our IFFHandle.
  68.     Bsr    CloseNudelClipboard    Close the Clipboard.
  69.  
  70.     RTS
  71.  
  72. WriteChunkBytes_Error
  73.     Move.l    NudelIFFHandle(a5),a0        -._ Pop the previously
  74.     N_CallIFFParse    PopChunk        -'  pushed chunk.
  75. ;;;;;;;    Ignore any error.
  76.     Bra_ErrorE_Int    ErrAct_IFFWriteChunkBytes(pc),#0    Fatal error.
  77.  
  78. PushChunk_Error_2
  79.     Move.l    NudelIFFHandle(a5),a0        -._ Pop the previously
  80.     N_CallIFFParse    PopChunk        -'  pushed chunk.
  81. ;;;;;;;    Tst.l    d0
  82. ;;;;;;;    Bne_ErrorE_Int    ErrAct_IFFPopChunk(pc),#0
  83. PushChunk_Error_1
  84.     Bra_ErrorE_Int    ErrAct_IFFPushChunk(pc),#0
  85.  
  86.  
  87.  
  88. ErrAct_IFFPushChunk
  89.     Dc.b    "PushChunk() failed",0
  90. ErrAct_IFFPopChunk
  91.     Dc.b    "PopChunk() failed",0
  92. ErrAct_IFFWriteChunkBytes
  93.     Dc.b    "WriteChunkBytes() failed",0
  94.     Even
  95.  
  96.  
  97. *= Allocate Nudel IFF =************************************************= 25-Aug-1995 =*
  98. *  Inputs: NudelIFFHandle(a5) - If non-null, Internal error.                  *
  99. * Outputs: NudelIFFHandle(a5) - Newly allocated IFFHandle.                  *
  100. *   Notes: Errors handled automatically and will abort the program.              *
  101. ***************************************************************************************
  102. AllocNudelIFF
  103.     Tst.l    NudelIFFHandle(a5)        -._ If previous use of handle
  104.     Bne    Internal            -'  not freed, internal error.
  105.     N_CallIFFParse    AllocIFF        Allocate IFFHandle.
  106.     Move.l    d0,NudelIFFHandle(a5)        Store it.
  107.     Beq_ErrorE_Int    ErrAct_AllocIFFHandle(pc),#0
  108.     RTS
  109. ErrAct_AllocIFFHandle
  110.     Dc.b    "Could not allocate IFFHandle",0
  111.     EVEN
  112.  
  113.  
  114. *= Free Nudel IFF =****************************************************= 25-Aug-1995 =*
  115. *  Inputs: NudelIFFHandle(a5) - IFFHandle to free.                      *
  116. * Outputs: NudelIFFHandle(a5) - NULL                              *
  117. *   Notes: Does not check that the structure has been closed with CloseIFF()          *
  118. ***************************************************************************************
  119. FreeNudelIFF
  120.     Tst.l    NudelIFFHandle(a5)        -._ If no handle was allocated,
  121.     Beq.s    FreeNudelIFF_Skip        -'  don't free anything.
  122.     Move.l    NudelIFFHandle(a5),a0        -._ Else, free
  123.     N_CallIFFParse    FreeIFF            -'  NudelIFFHandle.
  124.     Move.l    #0,NudelIFFHandle(a5)        NULL handle for future use.
  125. FreeNudelIFF_Skip
  126.     RTS
  127.  
  128.  
  129. *= Open Nudel Clipboard =**********************************************= 25-Aug-1995 =*
  130. *  Inputs: NudelIFFHandle(a5) - Init'd IFFHandle to point to clipboard stream.          *
  131. * Outputs: NudelIFFHandle(a5) - iff_stream points to clipboard handle.              *
  132. *          NudelClipboardHandle(a5) - ClipboardHandle for closing later.          *
  133. *   Notes: Always opens the 'primary' clipboard device, #0.                  *
  134. ***************************************************************************************
  135. OpenNudelClipboard
  136.     Tst.l    NudelClipboardHandle(a5)    -._ If previous ClipboardHandle
  137.     Bne    Internal            -'  not freed, internal error.
  138.  
  139.     Moveq    #PRIMARY_CLIP,d0        Want to open 'primary' unit (#0).
  140.     N_CallIFFParse    OpenClipboard        Open the clipboard.
  141.     Move.l    d0,NudelClipboardHandle(a5)    Store the handle.
  142.     Beq_ErrorE_Int    ErrAct_OpenClipboard(pc),#0
  143.  
  144.     Move.l    NudelIFFHandle(a5),a0        -._ Setup stream
  145.     Move.l    d0,iff_Stream(a0)        -'  in IFFHandle.
  146.  
  147.     RTS
  148. ErrAct_OpenClipboard
  149.     Dc.b    "Could not open Clipboard",0
  150.     Even
  151.  
  152.  
  153. *= Close Nudel Clipboard =*********************************************= 25-Aug-1995 =*
  154. *  Inputs: NudelClipboardHandle(a5) - ClipboardHandle for closing.              *
  155. * Outputs: NudelClipboardHandle(a5) - NULL.                          *
  156. *   Notes: NudelIFFHandle(a5)/iff_Stream is *NOT* altered and thus WILL be invalid    *
  157. *       after this routine if it was pointing to NudelClipboardHandle. This          *
  158. *       routine should *only* be used after the IFFHandle has been closed first.   *
  159. ***************************************************************************************
  160. CloseNudelClipboard
  161.     Tst.l    NudelClipboardHandle(a5)    -._ If handle isn't open,
  162.     Beq.s    CloseNudelClipboard_Skip    -'  skip the routine.
  163.     Move.l    NudelClipboardHandle(a5),a0    -._ Close the
  164.     N_CallIFFParse    CloseClipboard        -'  clipboard.
  165.     Move.l    #0,NudelClipboardHandle(a5)    Null handle for future use.
  166. CloseNudelClipboard_Skip
  167.     RTS
  168.  
  169.  
  170. *= Open NudelIFF =*****************************************************= 25-Aug-1995 =*
  171. *  Inputs: NudelIFFHandle(a5) - Init'd IFFHandle, including iff_Stream              *
  172. *       d0 - Mode to open with, either #IFFF_READ or #IFFF_WRITE.              *
  173. * Outputs: IFFHandle is open.                                  *
  174. *       SF1_OpenIFF,STD_F_1(a5) - Set (1)                          *
  175. ***************************************************************************************
  176. OpenNudelIFF
  177.     BTst    #SF1_OpenIFF,STD_F_1(a5)    -._ If the handle is already
  178.     Bne    Internal            -'  open, internal error.
  179.     Move.l    NudelIFFHandle(a5),a0        IFFHandle to open.
  180. ;;;;;;;    Move.l    d0,d0                Mode to open with.
  181.     N_CallIFFParse    OpenIFF            OpenIFF()
  182.     Tst.l    d0
  183.     Bne_ErrorE_Int    ErrAct_OpenIFF(pc),#0    #0 = SUCCESS, _NOT_ FAILURE.
  184.     BSet    #SF1_OpenIFF,STD_F_1(a5)    Mark it as open.
  185.     RTS
  186. ErrAct_OpenIFF
  187.     Dc.b    "Could not OpenIFF()",0
  188.     Even
  189.  
  190.  
  191. *= Close NudelIFF =****************************************************= 25-Aug-1995 =*
  192. *  Inputs: NudelIFFHandle(a5) - Open IFFHandle.                          *
  193. *       SF1_OpenIFF,STD_F_1(a5) - Routine skipped if clear (0)              *
  194. * Outputs: NudelIFFHandle(a50 - Closed IFFHandle.                      *
  195. *       SF1_OpenIFF,STD_F_1(a5) - Cleared (0)                      *
  196. ***************************************************************************************
  197. CloseNudelIFF
  198.     BClr    #SF1_OpenIFF,STD_F_1(a5)    -._ Mark as closed,
  199.     Beq.s    CloseNudelIFF_Skip        -'  and skip if no open.
  200.     Move.l    NudelIFFHandle(a5),a0        Handle for closure.
  201.     N_CallIFFParse    CloseIFF        Close it.
  202. CloseNudelIFF_Skip
  203.     RTS
  204.